Skip to content

Conversation

@pranavjain97
Copy link
Contributor

@pranavjain97 pranavjain97 commented Oct 16, 2025

TICKET: WP-6284

Fix s390x endianness issue in Solana transaction verification

Problem

On s390x (big-endian) architecture, @solana/web3.js incorrectly reads Solana's little-endian u64 amounts as big-endian during transaction parsing in Transaction.fromRawTransaction(). The library uses Node.js Buffer methods that are architecture-dependent, causing byte order misinterpretation.

This results in corrupted amounts when explainTransaction() is called:

  • Small amounts (e.g., 10,000 lamports) → appear as huge values (~1.16×10^18 lamports)
  • Large amounts (e.g., ~5×10^17 lamports) → appear as tiny values (7 lamports)

Both cases cause verifyTransaction() to fail when comparing parsed transaction amounts against user-provided recipients.

Root Cause

  • Solana stores amounts as u64 in little-endian format
  • @solana/web3.js parser uses Buffer reads that respect architecture endianness
  • On s390x, Buffer reads are big-endian by default
  • Result: Parser consistently reads all amounts with wrong byte order

Solution

Added getAmountBasedOnEndianness() helper function that:

  1. Detects s390x architecture via process.arch
  2. Byte-swaps all amounts to undo the parser's incorrect endianness interpretation
  3. Returns amounts unchanged on other architectures

Applied in verifyTransaction() when:

  • Comparing transaction outputs against user-provided recipients
  • Summing output amounts for total validation

@pranavjain97 pranavjain97 force-pushed the WP-6284-solana-bigendian-fix branch 4 times, most recently from fd47129 to c724981 Compare November 4, 2025 20:13
@pranavjain97 pranavjain97 marked this pull request as ready for review November 4, 2025 23:14
@pranavjain97 pranavjain97 requested a review from a team as a code owner November 4, 2025 23:14
@pranavjain97 pranavjain97 force-pushed the WP-6284-solana-bigendian-fix branch from c724981 to 96f3d34 Compare November 4, 2025 23:53
Copy link
Contributor

@margueriteblair margueriteblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests needed?

@pranavjain97
Copy link
Contributor Author

No tests needed?

yeah cant really have tests for this because the behavior woudnt be like s390x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants